package com.christodoulou.placesfinder;
import java.util.Locale;
import com.christodoulou.placesfinder.R.id;
import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

public class SingleListItem extends Activity {
	
	static final String KEY_NAME = "NAME";
	static final String KEY_TYPE = "BUSINESS_TYPE";
	static final String KEY_COUNTRY = "COUNTRY";
	static final String KEY_DISCRIPT = "DISCRIPT";
	static final String KEY_LATITUDE = "LATITUDE";
	static final String KEY_LONGITUDE = "LONGITUDE";
	static final String KEY_URL = "URL";
	
	
	String businessName;
	String businessType;
	String country;
	String businessDescription;
	String latitude;
	String longitude;
	String businessurl;
	
	
	public ImageLoader imageLoader; 

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_single_list_item);
		
		imageLoader=new ImageLoader(getApplicationContext());
        imageLoader.desiredImageSize = 400;
        
		
		// getting intent data
        Intent in = getIntent();
        
        // Get XML values from previous intent
        businessName = in.getStringExtra(KEY_NAME);
        businessType = in.getStringExtra(KEY_TYPE);
        country = in.getStringExtra(KEY_COUNTRY);
        businessDescription = in.getStringExtra(KEY_DISCRIPT);
        latitude = in.getStringExtra(KEY_LATITUDE);
        longitude = in.getStringExtra(KEY_LONGITUDE);
        businessurl =in.getStringExtra(KEY_URL);
        
        ImageView imgAlbum = (ImageView) findViewById(id.image);
        TextView txtName = (TextView) findViewById(R.id.name);
        TextView txtCountry = (TextView) findViewById(R.id.country);
        TextView txtDescription = (TextView) findViewById(R.id.description);
        TextView txtlatitude = (TextView) findViewById(R.id.latitude);
        TextView txtlongitude = (TextView) findViewById(R.id.longitude);
        

        imageLoader.DisplayImage(businessurl, imgAlbum);
        txtName.setText(businessName);
        txtCountry.setText(country);
        txtDescription.setText(businessDescription);
        txtlatitude.setText(latitude);
        txtlongitude.setText(longitude);
        
        Button buttonMap= (Button) findViewById(R.id.buttonSeeOnMap);
        buttonMap.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
            	String mapsUrl = String.format(Locale.ENGLISH, "https://maps.google.com/maps?q=%s,%s",latitude,longitude);
            	Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(mapsUrl));
            	startActivity(intent);
            }
        });
        
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.singleitem, menu);
		return true;
	}

}
